refs: Don't try searching for input strings that can't be objects
authorColin Walters <walters@verbum.org>
Wed, 23 Jul 2014 19:09:24 +0000 (15:09 -0400)
committerColin Walters <walters@verbum.org>
Wed, 23 Jul 2014 19:09:24 +0000 (15:09 -0400)
I noticed OSTree was a bit slower, did some investigation
and saw we were enumerating all objects for things like

$ ostree rev-parse blah

Since "blah" can never be an object (because of the 'l' and 'h'), just
return no matches.

src/libostree/ostree-repo-refs.c

index 978c5e0820eb507f2925acd2709c832daf9e9894..ca584b6626d3825929b73d0fb5890b0a2fcfac46 100644 (file)
@@ -364,6 +364,8 @@ ostree_repo_resolve_partial_checksum (OstreeRepo   *self,
                                       GError      **error)
 {
   gboolean ret = FALSE;
+  static const char hexchars[] = "0123456789abcdef";
+  gsize off;
   gs_unref_hashtable GHashTable *ref_list = NULL;
   gs_free char *ret_rev = NULL;
   guint length;
@@ -375,6 +377,12 @@ ostree_repo_resolve_partial_checksum (OstreeRepo   *self,
 
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
+  /* If the input is longer than 64 chars or contains non-hex chars,
+     don't bother looking for it as an object */
+  off = strspn (refspec, hexchars);
+  if (off > 64 || refspec[off] != '\0')
+    return TRUE;
+
   /* this looks through all objects and adds them to the ref_list if:
      a) they are a commit object AND
      b) the obj checksum starts with the partual checksum defined by "refspec" */